﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D04_Mathf3 : MonoBehaviour
{
    public Transform cubeA, cubeB, sphere;
    [Range(0, 1)]
    public float f;

    public float duration = 1;//持续时间
    private void Start1()
    {
        //Maht.Lertp(起点,终点,比例)
        print(Mathf.Lerp(5, 10, 0.5f));// 5到10的0.5位置  输出7.5

        print(Vector3.Lerp(new Vector3(0, 1, 2), new Vector3(0, 2, 5), 0.5f)); // (0,1.5,3.5)

        //Unity中  Vector3 Color  Quaternion 都可以插值
    }

    //根据f的值确sphere定在cubeA和cubeB之间的位置
    private void Update()
    {
        f += Time.deltaTime / duration;
        sphere.position = Vector3.Lerp(cubeA.position, cubeB.position, f);
    }
}